import { ipcMain } from 'electron'
export class IpcUtil {
  public static requests: Map<string, any> = new Map()
  static on(requestPath: string, cb: Function): void {
    ipcMain.on(requestPath, (event: any, arg: any) => {
      this.requests.set(arg.header.requestId, event)
      cb(arg.header.requestId, arg.params)
    })
  }
  static send(requestId: string, requestPath: string, reply: any): void {
    const res = { requestId: requestId, reply: reply }
    this.requests.get(requestId).sender.send(requestPath, res)
    this.requests.delete(requestId)
  }
}
